/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.gameai.tickettoride.core;

import java.util.ArrayList;
import java.util.HashMap;

/**
 *
 * @author Christopher
 */
public class Hand {
    
    private ArrayList<TrainCard> trainCards;
    private ArrayList<DestCard> destCards;
    
    public Hand() {
        trainCards = new ArrayList<TrainCard>();
        destCards = new ArrayList<DestCard>();
    }
    
    public void addCard(Card c) {
        if (c instanceof TrainCard) {
            trainCards.add((TrainCard) c);
        } else if (c instanceof DestCard) {
            destCards.add((DestCard) c);
        } else {
            System.out.println("INVALID CARD ADD ATTEMPT TO HAND");
        }
    }
    
    
    public int numDestCards(){
        return destCards.size();
    }
    
    public int numTrainCards(){
        return trainCards.size();
    }
    
      public boolean destComplete(ArrayList<Rail> rails_owned){
      ArrayList<Boolean> NOTcomplete = new ArrayList<Boolean>();
       for(DestCard dest_pair : destCards){
           NOTcomplete.add(!tickettoride.TtRgraph.connection_exist(dest_pair.getDestCities(), rails_owned));
       }
       
       for(Boolean b : NOTcomplete){
           if (b){
               return false;
           }
       }
       return true;
  }
    
    @Override
    public String toString(){
        return ("Train Cards: " + trainCards + "\n" + "Destination Cards: " + destCards);
    }
    
    public HashMap<Graph.COLOR, Integer> getHandColorsMap(){
        HashMap<Graph.COLOR, Integer> out = new HashMap<Graph.COLOR, Integer>();
        
        for(Graph.COLOR c: Graph.COLOR.values()){
            out.put(c, new Integer(0));
        }

        for(int i = 0; i < trainCards.size(); i++){
            out.put(trainCards.get(i).getCardColor(), out.get(trainCards.get(i).getCardColor())+1);
        }
        return out;
   }
    
    public Graph.COLOR[] getHandColors(){
        Graph.COLOR[] out = new Graph.COLOR[trainCards.size()];
            
        for(int i = 0; i < trainCards.size(); i++){
            out[i] = trainCards.get(i).getCardColor();
        }
        return out;
   }
}
